//
//  TradeOperateViewController.m
//  RedManStock
//
//  Created by lanou3g on 15/8/1.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "TradeOperateViewController.h"
#import "UIDefine.h"
#import "ParameterHeader.h"
#import "SimpleStock.h"
#import "DataHandle.h"
#import "MyHandle.h"
#import "MBProgressHUD.h"
#import "MyCoreHandle.h"
#import "AppDelegate.h"
@interface TradeOperateViewController ()<UITextFieldDelegate,UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain) NSMutableArray *stockArray;//总数据源
@property (nonatomic,retain) NSMutableArray *searchArray;//搜索结果数据源
@property (nonatomic,retain) UITableView *searchTableview;
@property (nonatomic,retain) User *myUser;
//获取AppDelegate中的status参数，用于判断是否处于交易状态
@property (nonatomic,assign) BOOL stockStatus;
@property (nonatomic,strong) NSManagedObjectContext *mContext;
@end

/**
 卖5-卖1 价格tag 11-15；成交量tag 21-25
 买1-买5 价格tag 31-35；成交量tag 41-45
 */

@implementation TradeOperateViewController
@synthesize tradeInfo;

- (BOOL)stockStatus{
    AppDelegate *myAppDelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
    return myAppDelegate.status;
}


- (NSManagedObjectContext *)mContext{
    if (_mContext!=nil) {
        return _mContext;
    }
    AppDelegate *myAppDelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
    _mContext=myAppDelegate.managedObjectContext;
    return _mContext;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //初始化
    tradeInfo=[[TradeInfo alloc]init];
    tradeInfo.buyPriceArray=[NSMutableArray array];
    tradeInfo.buyVolumeArray=[NSMutableArray array];
    tradeInfo.sellPriceArray=[NSMutableArray array];
    tradeInfo.sellVolumeArray=[NSMutableArray array];
    
    self.myUser=[NSKeyedUnarchiver unarchiveObjectWithFile: [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"user.plist"]];
    
    //从xib上读取出来
    self.tradeOperateView=[[[NSBundle mainBundle] loadNibNamed:@"TradeOperateView" owner:self options:nil] objectAtIndex:0];
    self.tradeInfoView=[[[NSBundle mainBundle] loadNibNamed:@"TradeInfoView" owner:self options:nil] objectAtIndex:0];
    self.view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64)];
    
    //头部显示的可用资金，高度30
    self.headLabel=[UILabel labelWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 30) fontSize:14 lineBreak:YES];
    self.headLabel.backgroundColor=MyGrayColor;
#warning 给最上方的可用资金用单例里的属性赋值
//    NSString *str=@"可用资金";
//    self.headLabel.text=[str stringByAppendingString:可用资金];
    [self.view addSubview:self.headLabel];
    
    //左侧的view
    self.tradeOperateView.frame=CGRectMake(0, 30, self.view.bounds.size.width*5/8,400);
//    self.view.bounds.size.width*5/8*11/10
    [self.view addSubview:self.tradeOperateView];
    
    //右侧的买5卖5
    self.tradeInfoView.frame=CGRectMake(self.view.bounds.size.width*5/8, 30, self.view.bounds.size.width*3/8, self.view.bounds.size.width*3/8*11/6);
    [self.view addSubview:self.tradeInfoView];
    
    //修改button的样式
    self.tradeOperateView.addButton.layer.borderColor=[UIColor colorWithWhite:0.844 alpha:1.000].CGColor;
    self.tradeOperateView.addButton.layer.borderWidth=0.5;
    self.tradeOperateView.minusButton.layer.borderColor=[UIColor colorWithWhite:0.844 alpha:1.000].CGColor;
    self.tradeOperateView.minusButton.layer.borderWidth=0.5;
    for (UIView *view in self.tradeOperateView.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            view.layer.cornerRadius=5;
        }
    }
    
    //通过buyOrSell
    [self setTradeType];
    
    //添加各种button的target，action
    [self setButtonActions];
    
    
    //textField实现下拉搜索的代理
    self.tradeOperateView.stockStrTF.delegate=self;
    [self.tradeOperateView.stockStrTF addTarget:self action:@selector(stockTextFieldDIdChange:) forControlEvents:UIControlEventEditingChanged];
    
    //textField搜索的下拉tableView
    self.searchTableview=[[UITableView alloc]initWithFrame:CGRectMake(self.tradeOperateView.stockStrTF.frame.origin.x, CGRectGetMaxY(self.tradeOperateView.stockStrTF.frame)+30, self.view.bounds.size.width*5/8-15, 100) style:UITableViewStylePlain];
    UIView *view=[[UIView alloc]initWithFrame:CGRectZero];
    self.searchTableview.tableFooterView=view;
    self.searchTableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.searchTableview.hidden=YES;
    self.searchTableview.dataSource=self;
    self.searchTableview.delegate=self;
    self.searchTableview.layer.borderWidth=1;
    self.searchTableview.layer.borderColor=[UIColor colorWithWhite:0.675 alpha:1.000].CGColor;
    [self.view addSubview:self.searchTableview];
    
    //搜索数据源初始化
    self.stockArray=[DataHandle shareHandle].allStockArray;
    self.searchArray=[NSMutableArray array];
    
}

//重写willAppear
- (void)viewWillAppear:(BOOL)animated{
    
    //其中来设置穿过来的code或者_buyOrSell
    if (self.sendCode && [self.sendCode length]>2) {
        //赋上该赋的值
        self.tradeOperateView.stockStrTF.text=self.sendCode;
        [self loadNewDataWithCode:self.sendCode];
    }
    
    //否则清空数据
    else{
        self.tradeOperateView.stockStrTF.text=nil;
        self.tradeOperateView.entrustPriceTF.text=nil;
        self.tradeOperateView.entrustVolumeTF.text=nil;
        self.tradeInfoView.stockStrLabel.text=[NSString stringWithFormat:@"股票名称(股票代码)"];
        self.tradeInfoView.nowPriceStrLabel.text=nil;
        
        for (int i=0; i<5; i++) {
            UILabel *label1=(UILabel *)[self.tradeInfoView viewWithTag:i+11];
            label1.text=@"--";
            UILabel *label2=(UILabel *)[self.tradeInfoView viewWithTag:i+21];
            label2.text=@"--";
            UILabel *label3=(UILabel *)[self.tradeInfoView viewWithTag:i+31];
            label3.text=@"--";
            UILabel *label4=(UILabel *)[self.tradeInfoView viewWithTag:i+41];
            label4.text=@"--";
        }
        
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    self.sendCode=nil;
}

- (void)setButtonActions{
    
    [self.tradeOperateView.oneFourButton addTarget:self action:@selector(oneFourButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tradeOperateView.oneTwoButton addTarget:self action:@selector(oneTwoButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tradeOperateView.oneButton addTarget:self action:@selector(oneButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tradeOperateView.tradeButton addTarget:self action:@selector(tradeButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tradeOperateView.marketTradeButton addTarget:self action:@selector(marketTradeButtonAction) forControlEvents:UIControlEventTouchUpInside];
}

#warning 按钮的功能
//买入的话，_buyOrSell为YES，同时传过来的sendCode有值,同时要获取到用户的可用资金
//卖出的话，_buyOrSell为NO，同时传过来的sendCode有值

//1/4
- (void)oneFourButtonAction{
    if (_buyOrSell) {
        if ([tradeInfo.nowPrice length]>2) {
            float a=[self.myUser.availableAsset floatValue]/[tradeInfo.nowPrice floatValue]*1/4;
            self.tradeOperateView.entrustVolumeTF.text=[NSString stringWithFormat:@"%.0f",a];
        }
    }
    else{
        self.tradeOperateView.entrustVolumeTF.text=[NSString stringWithFormat:@"%d",[self.position.availableVolume intValue]/4];
    }
}
//1/2
- (void)oneTwoButtonAction{
    if (_buyOrSell) {
        if ([tradeInfo.nowPrice length]>2) {
            float a=[self.myUser.availableAsset floatValue]/[tradeInfo.nowPrice floatValue]*1/2;
            self.tradeOperateView.entrustVolumeTF.text=[NSString stringWithFormat:@"%.0f",a];
        }
    }
    else{
        self.tradeOperateView.entrustVolumeTF.text=[NSString stringWithFormat:@"%d",[self.position.availableVolume intValue]/2];
    }
}
//全部
- (void)oneButtonAction{
    if (_buyOrSell) {
        if ([tradeInfo.nowPrice length]>2) {
            float a=[self.myUser.availableAsset floatValue]/[tradeInfo.nowPrice floatValue];
            self.tradeOperateView.entrustVolumeTF.text=[NSString stringWithFormat:@"%.0f",a];
        }
        
    }
    else{
        self.tradeOperateView.entrustVolumeTF.text=self.position.availableVolume;
    }
}
#pragma mark 买卖的button响应事件，肯定会把委托加入到数据库中
//买入/卖出
- (void)tradeButtonAction{
    if ([self.tradeOperateView.stockStrTF.text length]>0 &&
        [self.tradeOperateView.entrustPriceTF.text length]>0 &&
        [self.tradeOperateView.entrustVolumeTF.text length]>0) {
        
        int a=[self.tradeOperateView.entrustVolumeTF.text intValue];
        int b=a/100;
        if (b*100-a==0) {
            //判断是否超出委托的最大量
            int maxVolumeNum=0;
            if (_buyOrSell) {
                maxVolumeNum=(int)[self.myUser.availableAsset floatValue]/[tradeInfo.nowPrice floatValue];
            }
            else{
                maxVolumeNum=[self.position.availableVolume intValue];
            }
            
            if ([self.tradeOperateView.entrustVolumeTF.text intValue]>maxVolumeNum) {
                UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"百股经" message:@"买卖数量不能超过最大可交易数量" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [alertView show];
            }
            //成交
            else{
                
                
                SimpleStock *stock=[[SimpleStock alloc]init];
                stock.name=[self.tradeInfoView.stockStrLabel.text componentsSeparatedByString:@"("][0];
                stock.code=self.tradeOperateView.stockStrTF.text;
                stock.entrustPrice=self.tradeOperateView.entrustPriceTF.text;
                
                stock.volume=self.tradeOperateView.entrustVolumeTF.text;
                stock.nowPrice=self.tradeInfoView.nowPriceStrLabel.text;
                
                float tP=[stock.entrustPrice floatValue]*[stock.volume floatValue];
                if (_buyOrSell) {
                    stock.which=@"冻结资金";
                    
#warning 这里有个问题是，委托成交后，用户委托价是5.3, 但成交价是5.1，此时应该返还5.3*volume，股票市值改变的是5.1*volume,可用资产增加0.2*volume
                    // 提交买入委托后，必须要改变用户的账户(在委托失效后，要返还用户的可用资产；在委托成功后，要改变用户的可用资产)
                    User *myUser=[NSKeyedUnarchiver unarchiveObjectWithFile: [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"user.plist"]];
                    //只有可用资金会变化
                    myUser.availableAsset=[NSString stringWithFormat:@"%.2f",[myUser.availableAsset floatValue]-tP];
                    [NSKeyedArchiver archiveRootObject:myUser toFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"user.plist"]];
                    
                }
                else{
                    stock.which=@"交易金额";
                    
                    // 提交卖出委托后，用户的账户没有变，但position会有变化，持仓数量不变，但可卖数量会发生变化
                    MyCorePosition *position=[[MyCoreHandle shareHandle] selectPositionWithCode:stock.code];
                    
                    position.volume=[NSString stringWithFormat:@"%.0f",[position.volume floatValue]-[stock.volume floatValue]];
                    [self.mContext save:nil];
                    
                    
                }
                
                //委托成功后加入数据库
                [[MyCoreHandle shareHandle] addMyCoreEntrust:stock];
                [self setUpMBProgressWithText:@"委托成功"];
            }
        }
        else{
            [self setUpMBProgressWithText:@"委托数量必须为100的整数倍!"];
        }
    }
    else{
        [self setUpMBProgressWithText:@"请输入完整信息"];
    }
}
//市价买入/卖出
- (void)marketTradeButtonAction{
    //如果不是交易时间，则返回
    if (self.stockStatus==NO) {
        [self setUpMBProgressWithText:@"非交易时间，不能市价交易"];
        return;
    }
    if ([self.tradeOperateView.stockStrTF.text length]>0 &&
        [self.tradeOperateView.entrustPriceTF.text length]>0 &&
        [self.tradeOperateView.entrustVolumeTF.text length]>0) {
        
        int a=[self.tradeOperateView.entrustVolumeTF.text intValue];
        int b=a/100;
        //委托数量是100的整数倍
        if (b*100-a==0) {
            
            
            //判断是否超出委托的最大量
            int maxVolumeNum=0;
            if (_buyOrSell) {
                maxVolumeNum=(int)[self.myUser.availableAsset floatValue]/[tradeInfo.nowPrice floatValue];
            }
            else{
                maxVolumeNum=[self.position.availableVolume intValue];
            }
            
            if ([self.tradeOperateView.entrustVolumeTF.text intValue]>maxVolumeNum) {
                UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"百股经" message:@"买卖数量不能超过最大可交易数量" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [alertView show];
            }
            //成功
            else{
                SimpleStock *stock=[[SimpleStock alloc]init];
                stock.name=[self.tradeInfoView.stockStrLabel.text componentsSeparatedByString:@"("][0];
                stock.code=self.tradeOperateView.stockStrTF.text;
                stock.volume=self.tradeOperateView.entrustVolumeTF.text;
                stock.nowPrice=self.tradeInfoView.nowPriceStrLabel.text;
                
                //市价的时候，价格会根据现价来做+/-0.01的判断
                if (_buyOrSell) {
                    stock.which=@"冻结资金";
                    float c=[self.tradeInfoView.nowPriceStrLabel.text floatValue]+0.01;
                    stock.entrustPrice=[NSString stringWithFormat:@"%.2f",c];
                    
                    //委托成功后，必须要改变用户的账户
                    User *myUser=[NSKeyedUnarchiver unarchiveObjectWithFile: [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"user.plist"]];
                    
                    //只有可用资金会变化
                    float tP=c*[stock.volume floatValue];
                    myUser.availableAsset=[NSString stringWithFormat:@"%.2f",[myUser.availableAsset floatValue]-tP];
                    [NSKeyedArchiver archiveRootObject:myUser toFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"user.plist"]];
                    
                }
                else{
                    stock.which=@"交易金额";
                    float c=[self.tradeInfoView.nowPriceStrLabel.text floatValue]-0.01;
                    stock.entrustPrice=[NSString stringWithFormat:@"%.2f",c];
                    
                    // 提交卖出委托后，用户的账户没有变，但position会有变化，持仓数量不变，但可卖数量会发生变化
                    MyCorePosition *position=[[MyCoreHandle shareHandle] selectPositionWithCode:stock.code];
                    
                    position.volume=[NSString stringWithFormat:@"%.0f",[position.volume floatValue]-[stock.volume floatValue]];
                    [self.mContext save:nil];
                }
                
                //委托成功后加入数据库
                [[MyCoreHandle shareHandle] addMyCoreEntrust:stock];
                [self setUpMBProgressWithText:@"委托成功"];
            }
        }
        else{
            [self setUpMBProgressWithText:@"委托数量必须为100的整数倍!"];
        }
    }
    else{
        [self setUpMBProgressWithText:@"请输入完整信息"];
    }
}

- (void)setUpMBProgressWithText:(NSString *)text{
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode=MBProgressHUDModeText;
    hud.labelText=text;
    [hud hide:YES afterDelay:1.5f];
}


- (void)setTradeType{
    
    if (_buyOrSell) {
        //买入时用户交互开启
        self.tradeOperateView.stockStrTF.userInteractionEnabled=YES;
        //头部显示的东西
        self.headLabel.text=[NSString stringWithFormat:@"可用资金: %@元",self.myUser.availableAsset];
        
        //button样式
        [self.tradeOperateView.tradeButton setBackgroundColor:MyRedColor];
        [self.tradeOperateView.tradeButton setTitle:@"买入" forState:UIControlStateNormal];
        [self.tradeOperateView.marketTradeButton setBackgroundColor:MyRedColor];
        [self.tradeOperateView.marketTradeButton setTitle:@"市价买入" forState:UIControlStateNormal];
    }
    else{
        //卖出时用户交互关闭
        self.tradeOperateView.stockStrTF.userInteractionEnabled=NO;
        //头部label显示的东西
        self.headLabel.text=[NSString stringWithFormat:@"持仓数量:%@股  |  可卖数量:%@股",self.position.volume,self.position.availableVolume];
        
        [self.tradeOperateView.tradeButton setBackgroundColor:MyGreenColor];
        [self.tradeOperateView.tradeButton setTitle:@"卖出" forState:UIControlStateNormal];
        [self.tradeOperateView.marketTradeButton setBackgroundColor:MyGreenColor];
        [self.tradeOperateView.marketTradeButton setTitle:@"市价卖出" forState:UIControlStateNormal];
    }
}

- (void)stockTextFieldDIdChange:(UITextField *)textfield{
    if (![self.tradeOperateView.stockStrTF.text isEqualToString:@""]) {
        
        self.searchTableview.hidden=NO;
        NSString *str = self.tradeOperateView.stockStrTF.text;
        //我擦，这里竟然可以直接用数组中模型的某个属性来做判断，醉了
        NSPredicate *predicate=[NSPredicate predicateWithFormat:@"stockStr CONTAINS [CD] %@",str];
        NSMutableArray *tempArray =[NSMutableArray arrayWithArray:[self.stockArray filteredArrayUsingPredicate:predicate]];
        [self.searchArray removeAllObjects];
        for (int i=0; i<tempArray.count; i++) {
            [self.searchArray addObject:tempArray[i]];
            if (i==10) {
                break;
            }
        }
        [self.searchTableview reloadData];
    }
    else{
        self.searchTableview.hidden=YES;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 15;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.searchArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *tfIdentifier=@"textFieldSearchCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tfIdentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:tfIdentifier];
    }
    
    SimpleStock *stock=self.searchArray[indexPath.row];
    cell.textLabel.text=stock.name;
    cell.detailTextLabel.text=[NSString stringWithFormat:@"(%@)",stock.code];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SimpleStock *stock=self.searchArray[indexPath.row];
    self.tradeInfoView.stockStrLabel.text=stock.stockStr;
    self.searchTableview.hidden=YES;
    self.tradeOperateView.stockStrTF.text=stock.code;
    [self.tradeOperateView.stockStrTF resignFirstResponder];
    
//去请求网络，然后给右侧的cell赋值
    [self loadNewDataWithCode:stock.code];
    
}

//http://api.gongniucaijing.com/stock/tradeinfo?code=603308&idfa=7B7C9B42-5C18-4EEB-A0F8-6708DE081AAE&machine=iPhone%205&os=iPhone%20OS%208.2&platform=1&protocolVersion=1.0&qudao=0000001&resolution=640%2A1136&token=d58f02522dac7e698a4600c8b18ff02c0b9fa6df&uuid=BULLSTOCK-79460017-C3E5-45EC-B98C-1DD541A61127&version=1.9.0&versionCode=190

- (void)loadNewDataWithCode:(NSString *)code{
    NSString *url=@"http://api.gongniucaijing.com/stock/tradeinfo";
    [[MyHandle new] requestDataWithURLStr:url parameterBlock:^NSDictionary *{
        NSDictionary *dic=@{@"code":code};
        return dic;
    } successBlock:^(NSDictionary *responseDic) {
#warning status可能会定义成全局的一个属性，
        self.status=[responseDic objectForKey:@"status"];
        
        NSDictionary *dic=[responseDic objectForKey:@"data"];
        tradeInfo.nowPrice=[NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"nowPrice"] floatValue]];
        tradeInfo.close=[[dic objectForKey:@"close"] stringValue];
        tradeInfo.highPrice=[[dic objectForKey:@"highPrice"] stringValue];
        tradeInfo.lowPrice=[[dic objectForKey:@"lowPrice"] stringValue];
        for (int i=0; i<5; i++) {
            tradeInfo.buyPriceArray[i]=[NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"buyPrice"][i] floatValue]];
            tradeInfo.sellPriceArray[i]=[NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"sellPrice"][i] floatValue]];
            tradeInfo.sellVolumeArray[i]=[NSString stringWithFormat:@"%d",[[dic objectForKey:@"sellVolume"][i] intValue]/100];
            tradeInfo.buyVolumeArray[i]=[NSString stringWithFormat:@"%d",[[dic objectForKey:@"buyVolume"][i] intValue]/100];
        }
        [self setRightView];
        [self setLeftView];
        
    } errorBlock:^(NSError *error) {
         [MyHandle setUpMBProgressWithView:self.view Text:@"网络错误，请检查网络"];
    }];
}

- (void)setRightView{
    
    self.tradeInfoView.nowPriceStrLabel.text=[NSString stringWithFormat:@"现价: %@",tradeInfo.nowPrice];
    for (int i=0; i<5; i++) {
        UILabel *label1=(UILabel *)[self.tradeInfoView viewWithTag:i+11];
        label1.text=tradeInfo.sellPriceArray[i];
        UILabel *label2=(UILabel *)[self.tradeInfoView viewWithTag:i+21];
        label2.text=tradeInfo.sellVolumeArray[i];
        UILabel *label3=(UILabel *)[self.tradeInfoView viewWithTag:i+31];
        label3.text=tradeInfo.buyPriceArray[i];
        UILabel *label4=(UILabel *)[self.tradeInfoView viewWithTag:i+41];
        label4.text=tradeInfo.buyVolumeArray[i];
    }
    
}

- (void)setLeftView{
    
    if (_buyOrSell) {
        self.tradeOperateView.entrustPriceTF.text=[NSString stringWithFormat:@"%.2f",[tradeInfo.nowPrice floatValue]+0.01];
    }
    else{
        self.tradeOperateView.entrustPriceTF.text=[NSString stringWithFormat:@"%.2f",[tradeInfo.nowPrice floatValue]-0.01];
    }
    self.tradeOperateView.topPriceLabel.text=[NSString stringWithFormat:@"涨停:%.2f",[tradeInfo.highPrice floatValue]];
    self.tradeOperateView.bottomPriceLabel.text=[NSString stringWithFormat:@"跌停:%.2f",[tradeInfo.lowPrice floatValue]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
